//CDirectSound.h
#ifndef CDirectSoundH
#define CDirectSoundH
#include <mmsystem.h>
#include "dsound.h"

class CDirectSound
{
public:
	CDirectSound();
	~CDirectSound();

public:
	bool SetHwnd(HWND hWnd);
	bool SetAudioFormat(WORD wChannels,WORD wBitsPerSample,DWORD dwSamplesPerSec);
	bool Open(HWND hwnd);
	void Close();
	void ClearBuff();
	void Pause();
	void Resume();
	void Stop();
	void AddAudioStream(BYTE* pBuffer,DWORD nSize);

	BOOL SetVolume(LONG volume);
	BOOL GetVolume(LONG *volume);

public:
	/*If not input sound data,check directsound buffer,when none play sound data,stop play*/
	bool CheckPlayOffset();

private:
	bool RevisePlayOffset();

private:		
	void CopyDataToBuff(BYTE *AudioBuff,DWORD Size,bool SetPosition);

private:
	bool                m_bSetPlayPosition;
	bool                m_bIsPlayed;
	bool                m_bIsPaused;
	DWORD               m_dwPlay_Write_Offect;
	LPDIRECTSOUND       m_lpDirectSound;
	LPDIRECTSOUNDBUFFER m_lpBuffer;
	DWORD               m_dwBufferSize;
	DWORD               m_dwLastPlayPos;

private:
	WORD  m_wChannels;
	WORD  m_wBitsPerSample;
	DWORD m_dwSamples;

	HWND  m_hwnd;

private:
	LONG  m_lVolume;

private:
	DWORD  m_dwClearBufferSize;
	DWORD  m_dwSamplesPerSec;
	WORD   m_wBlockAlign;

};
#endif
